package com.wskeee.ec.managers
{
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.utils.Dictionary;

	public class KeyboardManager
	{
		private var keystate:Dictionary = new Dictionary();
		private var stage:Stage;
		
		public function KeyboardManager(stage:Stage):void
		{
			this.stage = stage;
			initEvent();
		}
		
		protected function initEvent():void
		{
			stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
		}
		
		protected function onKeyUp(event:KeyboardEvent):void
		{
			keystate[event.keyCode] = false;
		}
		
		protected function onKeyDown(event:KeyboardEvent):void
		{
			keystate[event.keyCode] = true;
		}
		
		//========================= act =========================
		/**
		 * ctrl是否为按下状态 
		 * @return 
		 * 
		 */
		public function get ctrlIsDown():Boolean
		{
			return keystate[Keyboard.CONTROL] == true;
		}
		public function get shiftIsDown():Boolean
		{
			return keystate[Keyboard.SHIFT] == true;
		}
		public function get altIsDown():Boolean
		{
			return keystate[Keyboard.ALTERNATE] == true;
		}
		public function get spaceIsDown():Boolean
		{
			return keystate[Keyboard.SPACE] == true;
		}
		
		public function get wIsDwon():Boolean
		{
			return keystate[Keyboard.W] == true;
		}
		public function get sIsDwon():Boolean
		{
			return keystate[Keyboard.S] == true;
		}
		public function get aIsDwon():Boolean
		{
			return keystate[Keyboard.A] == true;
		}
		public function get dIsDwon():Boolean
		{
			return keystate[Keyboard.D] == true;
		}
		
		public function get upIsDwon():Boolean
		{
			return keystate[Keyboard.UP] == true;
		}
		public function get downIsDwon():Boolean
		{
			return keystate[Keyboard.DOWN] == true;
		}
		public function get leftIsDwon():Boolean
		{
			return keystate[Keyboard.LEFT] == true;
		}
		public function get rightIsDwon():Boolean
		{
			return keystate[Keyboard.RIGHT] == true;
		}
		//========================= end =========================
	}
}